/*
 * @Description: 
 * @Version: 1.0
 * @Autor: 陈德平
 * @Date: 2020-04-16 16:57:37
 * @LastEditors: 陈德平
 * @LastEditTime: 2020-04-20 16:36:25
 */
import {mapConfig} from './config'
console.log(mapConfig);
let map = null;   
const installObj = {
    install: function (Vue, d) {
        if (map !== null) return;
        let style = {
                version: 8,
                sources: { 
                bd: mapConfig.source,//深色地图
                  szzb: mapConfig.source_szzb,//深圳周边
                  zj: mapConfig.source1,//道路注记
                  bd_qs: mapConfig.source_qs,//浅色地图
                  xqd_zj: mapConfig.source2,//兴趣点注记 
                  areas: {
                      type: "geojson",
                      data: {
                          features: [],
                          type: "FeatureCollection"
                      }
                  },
                  bianjieIn: {
                      type: "geojson",
                      data: {
                          features: [],
                          type: "FeatureCollection"
                      }
                  },
                  bianjieOut: {
                      type: "geojson",
                      data: {
                          features: [],
                          type: "FeatureCollection"
                      }
                  },
                  //遮盖数据源
                  coveredSource: {
                      type: "geojson",
                      data: {
                          features: [],
                          type: "FeatureCollection"
                      }
                  },
                  //wfs遮盖数据源
                  wfsCoveredSource: {
                      type: "geojson",
                      data: {
                          features: [],
                          type: "FeatureCollection"
                      }
                  },
                  //渐变线
                  bianjieLIneSource: {
                      type: "geojson",
                      data: {
                          features: [],
                          type: "FeatureCollection"
                      }
                  },
                },
                layers: [
                    //深圳周边图层 
                    {
                        id: "szzb_layer",
                        type: "raster",
                        source: "szzb",
                        "raster-opacity": 1,
                        minzoom: 10,
                        maxzoom: 15
                    },
                    // 底图图层
                    {
                        id: "base_layer",
                        type: "raster",
                        source: "bd",
                        "raster-opacity": 1
                    },
                    //底图浅色图层
                    {
                        id: "base_layer_qs",
                        type: "raster",
                        source: "bd_qs",
                        "raster-opacity": 1,
                        layout: {
                            "visibility": "none"
                        }
                    },
                    {
                        id: "bianjieIn_layer",
                        type: "line",
                        source: "bianjieIn",
                        layout: {
                            "line-join": "round",
                            "line-cap": "round"
                        },
                        paint: {
                            "line-color": "#00a2ff",
                            "line-width": 2
                        }
                    },
                    //为了鼠标移动显示坐标
                    {
                        id: "bianjieMouseIn_layer",
                        type: "line",
                        source: "bianjieIn",
                        layout: {
                            "line-join": "round",
                            "line-cap": "round"
                        },
                        paint: {
                            "line-opacity": 0,
                            "line-color": "#00a2ff",
                            "line-width": 20
                        }
                    },
                    //移动内边界高亮面
                    {
                        id: "fillIn_layer",
                        type: "fill",
                        source: "bianjieIn",
                        layout: {
                            visibility: "visible"
                        },
                        paint: {
                            "fill-opacity": 0,
                            "fill-color": "#00a2ff",
                            "fill-outline-color": "yellow"
                        }
                    },
                    {
                        id: "bianjie_layer",
                        type: "line",
                        source: "bianjieOut",
                        layout: {
                            "line-join": "miter",
                            "line-cap": "square"
                        },
                        paint: {
                            "line-color": "#00c6ff",
                            "line-width": 2,
                            "line-dasharray": [4, 10] // 虚线
                        }
                    },
                    {
                        id: "area_Layer",
                        type: "line",
                        source: "areas",
                        layout: {
                            "line-join": "round",
                            "line-cap": "round"
                        },
                        paint: {
                            // "line-pattern":"rediamge", 
                            "line-color": "#00a2a2",
                            "line-width": 2
                        },
                        filter: ["==", "areacode", ""]
                    },
                    //遮盖图层 空隙
                    {
                        'id': 'coveredLayer',
                        type: "fill",
                        source: "coveredSource",
                        layout: {
                        },
                        paint: {
                            "fill-opacity": 1,
                            "fill-color": "#02123c",
                            //"fill-outline-color": "yellow"
                            // "fill-extrusion-opacity": 1,
                            // "fill-extrusion-color": '#02123c',
                            // "fill-extrusion-height": ["get", "height"]
                        },
                    },
                    // wmts注记图层
                    {
                        id: "base1_layer",
                        type: "raster",
                        source: "zj",
                        minzoom: 14,
                        "raster-opacity": 1
                    },
                    // 兴趣点注记图层
                    {
                        id: "base_xqd_layer",
                        type: "raster",
                        source: "xqd_zj",
                        minzoom: 14,
                        "raster-opacity": 1
                    },
                    //遮盖图层 wfs----解决注记压盖问题
                    {
                        'id': 'wfsCoveredLayer',
                        type: "fill",
                        source: "wfsCoveredSource",
                        layout: {
                        },
                        paint: {
                            "fill-opacity": 1,
                            "fill-color": "#02123c",
                            //"fill-color": "red",
                            // "fill-extrusion-opacity": 1,
                            // "fill-extrusion-color": '#02123c',
                            // "fill-extrusion-height": ["get", "height"]
                        },
                    },
                    //渐变线图层
                    {
                        id: "bianjieLine_layer",
                        type: "line",
                        source: "bianjieLIneSource",
                        layout: {
                            "line-join": "round",
                            "line-round-limit": 10000,
                            "line-cap": "round"
                        },
                        paint: {
                            "line-opacity": .3,
                            "line-color": "#23387a",
                            "line-width": 16,
                            "line-offset": -8,
                            // "line-pattern":"rediamge", 
                        }
                    },
                ]
              };
              //构造地图对象实例,并添加到id为map的div容器中
              map = new GeoGlobe.Map({
                mapCRS: { 
                  topTileExtent: [-180, -270, 180, 90],// wgs84 顶层瓦片范围 
                  coordtransform: "none"
                },
                style: style,
                container: 'map',
                zoom: 10,
                minZoom: 10,
                maxZoom: 24,
                units: "degrees", 
                center: mapConfig.center,
                pitch3Dzoom: 18 // 自动倾斜的层级
              });    
        // map = new GeoGlobe.Map({
        //     mapCRS: mapConfig.mapCRS,
        //     style: {
        //         version: 8,
        //         sources: {
        //             // source
        //             bd: mapConfig.source,//深色地图
        //             szzb: mapConfig.source_szzb,//深圳周边
        //             zj: mapConfig.source1,//道路注记
        //             bd_qs: mapConfig.source_qs,//浅色地图
        //             xqd_zj: mapConfig.source2,//兴趣点注记
        //             "areas": {
        //                 type: "geojson",
        //                 data: {
        //                     features: [],
        //                     type: "FeatureCollection"
        //                 }
        //             },
        //             "bianjieIn": {
        //                 type: "geojson",
        //                 data: {
        //                     features: [],
        //                     type: "FeatureCollection"
        //                 }
        //             },
        //             "bianjieOut": {
        //                 type: "geojson",
        //                 data: {
        //                     features: [],
        //                     type: "FeatureCollection"
        //                 }
        //             },
        //             //遮盖数据源
        //             "coveredSource": {
        //                 type: "geojson",
        //                 data: {
        //                     features: [],
        //                     type: "FeatureCollection"
        //                 }
        //             },
        //             //wfs遮盖数据源
        //             "wfsCoveredSource": {
        //                 type: "geojson",
        //                 data: {
        //                     features: [],
        //                     type: "FeatureCollection"
        //                 }
        //             },
        //             //渐变线
        //             "bianjieLIneSource": {
        //                 type: "geojson",
        //                 data: {
        //                     features: [],
        //                     type: "FeatureCollection"
        //                 }
        //             },
        //         },
        //         layers: [
        //             //深圳周边图层 
        //             {
        //                 id: "szzb_layer",
        //                 type: "raster",
        //                 source: "szzb",
        //                 "raster-opacity": 1,
        //                 minzoom: 10,
        //                 maxzoom: 15
        //             },
        //             // 底图图层
        //             {
        //                 id: "base_layer",
        //                 type: "raster",
        //                 source: "bd",
        //                 "raster-opacity": 1
        //             },
        //             //底图浅色图层
        //             {
        //                 id: "base_layer_qs",
        //                 type: "raster",
        //                 source: "bd_qs",
        //                 "raster-opacity": 1,
        //                 layout: {
        //                     "visibility": "none"
        //                 }
        //             },
        //             {
        //                 id: "bianjieIn_layer",
        //                 type: "line",
        //                 source: "bianjieIn",
        //                 layout: {
        //                     "line-join": "round",
        //                     "line-cap": "round"
        //                 },
        //                 paint: {
        //                     "line-color": "#00a2ff",
        //                     "line-width": 2
        //                 }
        //             },
        //             //为了鼠标移动显示坐标
        //             {
        //                 id: "bianjieMouseIn_layer",
        //                 type: "line",
        //                 source: "bianjieIn",
        //                 layout: {
        //                     "line-join": "round",
        //                     "line-cap": "round"
        //                 },
        //                 paint: {
        //                     "line-opacity": 0,
        //                     "line-color": "#00a2ff",
        //                     "line-width": 20
        //                 }
        //             },
        //             //移动内边界高亮面
        //             {
        //                 id: "fillIn_layer",
        //                 type: "fill",
        //                 source: "bianjieIn",
        //                 layout: {
        //                     visibility: "visible"
        //                 },
        //                 paint: {
        //                     "fill-opacity": 0,
        //                     "fill-color": "#00a2ff",
        //                     "fill-outline-color": "yellow"
        //                 }
        //             },
        //             {
        //                 id: "bianjie_layer",
        //                 type: "line",
        //                 source: "bianjieOut",
        //                 layout: {
        //                     "line-join": "miter",
        //                     "line-cap": "square"
        //                 },
        //                 paint: {
        //                     "line-color": "#00c6ff",
        //                     "line-width": 2,
        //                     "line-dasharray": [4, 10] // 虚线
        //                 }
        //             },
        //             {
        //                 id: "area_Layer",
        //                 type: "line",
        //                 source: "areas",
        //                 layout: {
        //                     "line-join": "round",
        //                     "line-cap": "round"
        //                 },
        //                 paint: {
        //                     // "line-pattern":"rediamge", 
        //                     "line-color": "#00a2a2",
        //                     "line-width": 4
        //                 },
        //                 filter: ["==", "areacode", ""]
        //             },
        //             //遮盖图层 空隙
        //             {
        //                 'id': 'coveredLayer',
        //                 type: "fill",
        //                 source: "coveredSource",
        //                 layout: {
        //                 },
        //                 paint: {
        //                     "fill-opacity": 1,
        //                     "fill-color": "#02123c",
        //                     //"fill-outline-color": "yellow"
        //                     // "fill-extrusion-opacity": 1,
        //                     // "fill-extrusion-color": '#02123c',
        //                     // "fill-extrusion-height": ["get", "height"]
        //                 },
        //             },
        //             // wmts注记图层
        //             {
        //                 id: "base1_layer",
        //                 type: "raster",
        //                 source: "zj",
        //                 minzoom: 14,
        //                 "raster-opacity": 1
        //             },
        //             // 兴趣点注记图层
        //             {
        //                 id: "base_xqd_layer",
        //                 type: "raster",
        //                 source: "xqd_zj",
        //                 minzoom: 14,
        //                 "raster-opacity": 1
        //             },
        //             //遮盖图层 wfs----解决注记压盖问题
        //             {
        //                 'id': 'wfsCoveredLayer',
        //                 type: "fill",
        //                 source: "wfsCoveredSource",
        //                 layout: {
        //                 },
        //                 paint: {
        //                     "fill-opacity": 1,
        //                     "fill-color": "#02123c",
        //                     //"fill-color": "red",
        //                     // "fill-extrusion-opacity": 1,
        //                     // "fill-extrusion-color": '#02123c',
        //                     // "fill-extrusion-height": ["get", "height"]
        //                 },
        //             },
        //             //渐变线图层
        //             {
        //                 id: "bianjieLine_layer",
        //                 type: "line",
        //                 source: "bianjieLIneSource",
        //                 layout: {
        //                     "line-join": "round",
        //                     "line-round-limit": 10000,
        //                     "line-cap": "round"
        //                 },
        //                 paint: {
        //                     "line-opacity": .3,
        //                     "line-color": "#23387a",
        //                     "line-width": 16,
        //                     "line-offset": -8,
        //                     // "line-pattern":"rediamge", 
        //                 }
        //             },
        //         ]
        //     }, // mapConfig.style,
        //     container: d,
        //     units: mapConfig.units, // 可以不需要设置
        //     minZoom: 10,
        //     maxZoom: 24,
        //     center: mapConfig.center,
        //     zoom: mapConfig.zoom,
        //     // pitch: 0, // 房屋、法人专题页面才倾斜
        //     // bearing: 0,
        //     // epsg: "EPSG:4490",
        //     // doubleClickZoom: false,
        //     // doubleClickZoom: false,
        //     // isIntScrollZoom: false, // 缩放级别是否为整数处理模式
        //     // renderWorldCopies: false,
        //     // isAttributionControl: false,
        //     // is3Dpitching: false, //! !(window.build || window.LegalPerson), //房屋、法人专题页面到指定层级自动倾斜
        //     pitch3Dzoom: 18 // 自动倾斜的层级
            
        // });
        map.dragRotate.disable(); //禁止鼠标翻转地图

        /*
        map.on("zoomend", function(){
            let zoom = map.getZoom();
            let pitch = map.getPitch();
            if(zoom >= 17.5 && pitch <= 25){
                map.flyTo({
                    speed: 2,
                    curve: 1,
                    pitch: 60,
                    easing(t) {
                        return t;
                    }
                });
            }else if(zoom < 17.5 && pitch >= 35){
                map.flyTo({
                    speed: 2,
                    curve: 1,
                    pitch: 0,
                    easing(t) {
                        return t;
                    }
                });
            }
        })
        */
        // markers = new Markers(map);
        // map.on("style.load", () => {
        //     if (hasLoaded) return;
        //     hasLoaded = true;
        //     onMapLoadArray.forEach((callback) => {
        //         try {
        //             callback(map)
        //         }
        //         catch (e) {
        //             console.log(e)
        //         }
        //     });
        // });
        // 添加地图自带的Control。-----需要提取成单独的函数。
        // const nav = new mapboxgl.NavigationControl();
        // map.addControl(nav, "bottom-right");
        Vue.prototype.$map = map
    }
}
export default installObj